package com.ncmmall.application.jobs;

import com.ncmmall.application.business.order.OrderApplication;
import lombok.extern.slf4j.Slf4j;
import org.quartz.JobExecutionContext;
import org.springframework.scheduling.quartz.QuartzJobBean;

/**
 * 自动取消订单作业调度，每分钟执行一次
 *
 * @author linxs
 * @date 2019-07-22 10:28
 */
@Slf4j
public class AutoCancelOrderJobSchedulingApplication extends QuartzJobBean {

    private final OrderApplication orderApplication;

    public AutoCancelOrderJobSchedulingApplication(OrderApplication orderApplication) {
        this.orderApplication = orderApplication;
    }

    public void execute() {
        try {
            log.info("[订单作业调度启动]");
            orderApplication.autoCancelOrders();
            log.info("[订单作业调度执行完成]");
        } catch (Exception e) {
            log.error("[订单作业调度执行异常]", e);
        }

        try {
            orderApplication.autoPayDistributionOrder();
        } catch (Exception e) {
            e.printStackTrace();
        }

        try {
            orderApplication.autoPayLiveOrder();
        } catch (Exception e) {
            e.printStackTrace();
        }


    }

    @Override
    protected void executeInternal(JobExecutionContext context) {

    }
}
